package com.lsp.base;

import android.app.Application;
import android.content.Context;
import com.blankj.utilcode.utils.Utils;
import com.lsp.base.utils.rxpreference.GlobalPreferencesManager;

/**
 * @author com.lsp.ibxs
 * @created 16/11/8 14:02
 */
public class BaseApplication extends Application {

  private static BaseApplication instance;
  public static boolean isUploadImg = false;
  public static boolean isShowQiniu = false;

  @Override public void onCreate() {
    super.onCreate();
    instance = this;
    Utils.init(this);
    initDagger();
    initRxPreference();
    initTangram();
  }

  private void initTangram() {
    //TangramBuilder.init(this, new IInnerImageSetter() {
    //  @Override public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view,
    //      @Nullable String url) {
    //    WyImageLoader.getInstance().display(BaseApplication.this,url,view, WyImageOptions.NONE);
    //  }
    //},ImageView.class);
  }

  /**
   * 初始化rxpreference
   */
  private void initRxPreference() {
    GlobalPreferencesManager.getInstance().init(this);
  }

  private void initDagger() {
    //DaggerBuilder.buildApplicationComponent(this).inject(this);
  }

  public static BaseApplication getInstance() {
    return instance;
  }

  /**
   * 退出应用程序
   */
  public void AppExit(Context context) {
    try {
      // 杀死该应用进程
      android.os.Process.killProcess(android.os.Process.myPid());
      System.exit(0);
    } catch (Exception e) {
    }
  }
}
